//在page页面引入app，同时声明变量，获得所需要的全局变量
const app = getApp();
const path = app.globalData.path;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    todoList: []
  },
  notificationCheck: function() {
    var that = this;
    let loginFlag = wx.getStorageSync('token');
    // 查询未读的Qi问题 通知数量  
    wx.request({
      url: path + 'wx-mw/notify-list!getNotifyListCount.action',
      header: {
        'token': loginFlag
      },
      dataType: "JSON",
      success: function(res) {
        console.log(res);
        var result = JSON.parse(res.data);
        that.setData({
          unreadNoticeCount: result.data.count
        })
        console.log(that.data.unreadNoticeCount);
      },
      fail: function(res) {

      }
    })
  },
  jumpToNotification: function() {
    var that = this;
    wx.navigateTo({
      url: '../../notification/notification'
    })
  },

  jumpToEdit: function(e) {
    var index = parseInt(e.currentTarget.dataset.index);
    var dataset = e.currentTarget.dataset;
    console.log(dataset.processStatus);

    if (dataset.processstatus == "SUBMIT" && dataset.lifecyclestatus == "OPEN") { 
      wx.navigateTo({ 
        url: '../../issue/issueList/issueDraft?issueId=' + dataset.issueid + 
        '&processStatus=' + dataset.processstatus + 
        '&lifecycleStatus=' + dataset.lifecyclestatus + 
        '&programVehicleId=' + dataset.programvehiclei
      }); 
    } else { 
      wx.navigateTo({ 
        url: '../todo/todoform?issueId=' + dataset.issueid + 
          '&processStatus=' + dataset.processstatus + 
          '&lifecycleStatus=' + dataset.lifecyclestatus + 
          '&programVehicleId=' + dataset.programvehicleid 
      });
    } 
    
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {


    // 查看前端页面是否有token token 存在去腾讯服务器检查session_key 是否过期
    
  },




  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    var that = this;
    let loginFlag = wx.getStorageSync('token');
    console.log(loginFlag);
    if (loginFlag != "") { 
      
      wx.request({
        url: path + 'wx-mw/todo-list!getTodoListQI.action',
        header: {
          'token': loginFlag
        },
        dataType: "JSON",
        success: function(res) {
          console.log(res);
          let result = JSON.parse(res.data);
          that.setData({
            todoList: result.data
          })
        },
        fail: function(res) {

        }
      })
      
    } else {
      console.log("else");
      // 无skey，作为首次登录
      wx.navigateTo({
        url: '../../login/login',
      })
    }

    that.notificationCheck();

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {
    var that = this;
    that.onLoad();
    wx.showNavigationBarLoading()
    setTimeout(() => {
      // this.getData = '数据拿到了'
      wx.stopPullDownRefresh()
      wx.hideNavigationBarLoading()
      // this.$apply()
    }, 3000)
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})